package com.ctsi.framework.security.core.authorize;

import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @Auther: zhangjw
 * @Date: 2018/7/1 12:24
 * @Description: 核心模块的授权配置提供器，安全模块涉及的url的授权配置在这里。
 */
@Component
@Order(Integer.MIN_VALUE)
public class DefaultAuthorizeConfigProvider implements AuthorizeConfigProvider {

     static final String[] arr = {"243898ac-8dc7-4dda-9d9f-85102ed5b28e",
             "4552bcb1-14ca-475a-b8d9-f25ab2b7ba25",
             "46cf442b-99ee-4819-a79a-3697521d06fe",
             "6b782774f9bf11e89c8f0235d2b38928",
             "6b782775f9bf11e89c8f0235d2b38928",
             "6b782776f9bf11e89c8f0235d2b38928",
             "6b782777f9bf11e89c8f0235d2b38928",
             "6b782778f9bf11e89c8f0235d2b38928",
             "6b782779f9bf11e89c8f0235d2b38928",
             "6b78277af9bf11e89c8f0235d2b38928",
             "6b78277bf9bf11e89c8f0235d2b38928",
             "6b78277cf9bf11e89c8f0235d2b38928",
             "6b78277df9bf11e89c8f0235d2b38928",
             "6b78277ef9bf11e89c8f0235d2b38928",
             "6b78277ff9bf11e89c8f0235d2b38928",
             "6b782780f9bf11e89c8f0235d2b38928",
             "6b782781f9bf11e89c8f0235d2b38928",
             "6b782782f9bf11e89c8f0235d2b38928","security_srole_admin"};

    @Override
    public boolean config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        config.antMatchers("/druid/**",
                "/product-imgs/**", //静态资源不控制权限
                "/auth/**",
                "/images/**",
                "/swagger-ui.html",
                "/axios/**",
                "/heyui/**",
                "/favicon.ico",
                "/swagger-resources/**",
                "/v2/api-docs",
                "/error",
                "/api/file/**",
                "/valid-code/**",
                "/support-app/version",
                "/crm-sync/sync",
                "/error/**").permitAll();
        config.antMatchers("/sysmenu/add").hasRole("security_srole_admin"); // 添加菜单
        config.antMatchers("/sysmenu/edit").hasRole("security_srole_admin"); // 编辑菜单
        config.antMatchers("/sysmenu/delete").hasRole("security_srole_admin"); // 删除菜单


        config.antMatchers("/dict/dictTypePage").hasRole("security_srole_admin"); // 字典管理
        config.antMatchers("/dict/update").hasRole("security_srole_admin"); // 字典管理
        config.antMatchers("/dict/updateisdel").hasRole("security_srole_admin"); // 字典管理
        config.antMatchers("/dict/addDictType").hasRole("security_srole_admin");
        config.antMatchers("/dict/addDictData").hasRole("security_srole_admin");
        config.antMatchers("/dict/updateData").hasRole("security_srole_admin");
        config.antMatchers("/dict/updateDatadel").hasRole("security_srole_admin");
        config.antMatchers("/dict/removeDatas").hasRole("security_srole_admin");

        config.antMatchers("/dicttree/types").hasRole("security_srole_admin");
        config.antMatchers("/dicttree/typess").hasRole("security_srole_admin");
        config.antMatchers("/dicttree/updateDictTreeType").hasRole("security_srole_admin");
//        config.antMatchers("/dicttree/datas").hasRole("security_srole_admin");
        config.antMatchers("/dicttree/updateDictTreeData").hasRole("security_srole_admin");
        config.antMatchers("/dicttree/deleteDictTreeData").hasRole("security_srole_admin");
        config.antMatchers("/dicttree/deleteDictTreeType").hasRole("security_srole_admin");

        config.antMatchers("/security/roles-query").hasAnyRole(arr);// 管理员或者地市管理员
        config.antMatchers("/security/delete-role").hasRole("security_srole_admin");
        config.antMatchers("/security/saverole").hasRole("security_srole_admin");
        config.antMatchers("/srole/save-role-permission/**").hasRole("security_srole_admin");
        config.antMatchers("/srole/del-role-permission").hasRole("security_srole_admin");
        config.antMatchers("/srole/save-dataobejcts/**").hasRole("security_srole_admin");
        config.antMatchers("/srole/delete-role-dataobject").hasRole("security_srole_admin");
        config.antMatchers("/srole/members").hasAnyRole(arr); // 管理员或者地市管理员

        config.antMatchers("/srole/add-role-users").hasAnyRole(arr); // 管理员或者地市管理员
        config.antMatchers("/srole/del-role-user").hasAnyRole(arr); // 管理员或者地市管理员


        config.antMatchers("/product/addorEditProduct").hasRole("security_srole_admin");
        config.antMatchers("/product/deleteByPrimaryKey").hasRole("security_srole_admin");


        config.antMatchers("/organise/organises").hasAnyRole(arr);// 管理员或者地市管理员
        config.antMatchers("/organise/update").hasAnyRole(arr);; // 管理员或者地市管理员
        config.antMatchers("/person/add").hasAnyRole(arr);
        config.antMatchers("/person/update").hasAnyRole(arr);
        config.antMatchers("/person/physic/**").hasAnyRole(arr);
        config.antMatchers("/person/logic/**").hasAnyRole(arr);



        return false;
    }

}
